<?php

	// TITLE: Notes AUTO MODEL
	// FILE: scaffolding/model/notes.php
	// AUTHOR: AUTOGEN
	// CREATED: 2015/04/20 07:49:57
	// DESCRIPTION: 
	// REQUIREMENTS: 

	$createNotes = function($con, $notes) {
		$sql = 'INSERT INTO notes (id, note, author_id, author_date) VALUES (';
		$sql .= $notes->getId() . ', ';
		$sql .= $notes->getNote() . ', ';
		$sql .= $notes->getAuthorId() . ', ';
		$sql .= $notes->getAuthorDate() . ')';
		$sql .= ')';
		$result = mysqli_query($con, $sql);
		$id = ($result) ? mysqli_insert_id($con) : $result;
		mysqli_close($con);
		return $id;
	};

	$readNotes = function($con, $id) {
		$sql = 'SELECT * FROM notes WHERE id = ' . $id;
		$results = mysqli_query($con, $sql);
		mysqli_close($con);
		if ($results) {
			$result = mysqli_fetch_array($results);
			$notes = new Notes();
			$notes->setId(result[0]);
			$notes->setNote(result[1]);
			$notes->setAuthorId($dbio->select($readAuthor(result[2])));
			$notes->setAuthorDate(result[3]);
		} else {
			$notes = false;
		}
		return $notes;
	};

	$updateNotes = function($con, $notes) {
		$sql = 'UPDATE notes SET ';
		$sql .= 'id = ' . $notes->getId() . ', ';
		$sql .= 'note = ' . $notes->getNote() . ', ';
		$sql .= 'author_id = ' . $notes->getAuthorId() . ', ';
		$sql .= 'author_date = ' . $notes->getAuthorDate() ;
		$sql .= 'WHERE id = ' . id;
		$result = mysqli_query($con, $sql);
		mysqli_close($con);
		return $result;
	};

	$deleteNotes = function($con, $id) {
		$sql = 'DELETE FROM notes WHERE id = ' . $id;
		$result = mysqli_query($con, $sql);
		mysqli_close($con);
		return $result;
	};

	$listNotes = function($con) {
		$sql = 'SELECT * FROM notes';
		$results = mysqli_query($con, $sql);
		mysqli_close($con);
		if ($results) {
			$notess = array();
			while ($result = mysqli_fetch_array($results)) {
				$notes = new Notes();
				$notes->setId(result[0]);
				$notes->setNote(result[1]);
				$notes->setAuthorId($dbio->select($readAuthor(result[2])));
				$notes->setAuthorDate(result[3]);
				$notess[] = notes;
			}// end while
		} else {
			$notess = false;
		}
		return $notess;
	};

